from api_middleware.middleware_error import error_middleware
from api_middleware.middleware_http import GlobalRequestMiddleware
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware


def middleware(app: FastAPI):

    app.add_middleware(
        CORSMiddleware,
        allow_origin_regex='https?://.*',  # 改成用正则就行了
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    app.add_middleware(GlobalRequestMiddleware)
    error_middleware(app)
